#ifndef __DETU_MEDIA_SYS_CTRL_MGR_IMP_H__
#define __DETU_MEDIA_SYS_CTRL_MGR_IMP_H__

#include "sys_ctrl_mgr.h"
#include "singleton.h"
#include "defs.h"
#include "mutex.h"

#include "hi_comm_vb.h"
#include "hi_common.h"

namespace detu_media
{
class SysCtrlMgrImp: public SysCtrlMgr
{
PATTERN_SINGLETON_DECLARE(SysCtrlMgrImp)

public:

	virtual S_Result start(void);
	
	virtual S_Result stop(void);
	
	virtual bool isStarted(void);
	
	virtual S_Result setViVpssMode(const Json::Value& config);

	virtual S_Result bind(const Json::Value& config);

	virtual S_Result unbind(const Json::Value& config);

	virtual S_Result mmzAlloc(Uint64_t* pu64PhyAddr, void** ppVirAddr,
                                  const char* pstrMmb, const char* pstrZone, Uint32_t u32Len);

	virtual S_Result mmzFree(Uint64_t u64PhyAddr, void* pVirAddr);

    virtual S_Result mmzAlloc_Cached(Uint64_t* pu64PhyAddr, void ** ppVirAddr,
                                                const char* pstrMmb, const char* pstrZone, Uint32_t u32Len);

    virtual void* mMap(Uint64_t u64PhyAddr, Uint32_t u32Size);
    
    virtual S_Result mmUnMap(void  *  pVirAddr, Uint32_t u32Size);

    virtual Uint32_t  getBlock(Uint32_t    Pool,Uint64_t u64BlkSize,char* pcMmzName);

    virtual Int32_t releaseBlock(Uint32_t Block);

    virtual Uint64_t handle2PhysAddr(Uint32_t Block);

private:
	S_Result initVb(const Json::Value& config);

	S_Result deInitVb(void);

	S_Result initSystem(void);

	S_Result deInitSystem(void);

	S_Result getSrcIdByName(const Json::Value& config, MPP_CHN_S& id);

	S_Result getDstIdByName(const Json::Value& config, MPP_CHN_S& id);

	S_Result startSrc(const Json::Value& config);

	S_Result stopSrc(const Json::Value& config);

private:
	VB_SUPPLEMENT_CONFIG_S fSupplementConf;
	VB_CONFIG_S fVbConf;
	bool fStarted;

	detu_infra::Mutex fMutex;
};

}

#endif

